namespace SimpleWebServices.Configuration
{
    using System;
    using System.Web.Mvc;
    using System.Xml.Serialization;
    using SimpleWebServices.Models;

    [XmlRoot("processor")]
    public sealed class SubmissionProcessorSetting : IProcessSubmission
    {
        [XmlAttribute("id")]
        public string Id
        {
            get;
            set;
        }

        public ActionResult Process(FormSubmission submission)
        {
            if (null == submission)
            {
                throw new ArgumentNullException("submission");
            }

            ActionResult result = null;

            if (string.IsNullOrEmpty(this.Id))
            {
                result = ServiceLocator.Resolve<IProcessSubmission>().Process(submission);
            }
            else
            {
                result = ServiceLocator.Resolve<IProcessSubmission>(this.Id).Process(submission);
            }

            return result;
        }
    }
}